<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/news.css"/>
    <style>
        li {
            list-style: inherit !important;
        }
    </style>
</head>

<body class="childrenBody">
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">昵称</label>
        <div class="layui-input-block">
            <input type="text" lay-verify="required" placeholder="请输入昵称" class="layui-input"
                   id="nickname">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">手机号码</label>
        <div class="layui-input-block">
            <input type="text" lay-verify="required"  placeholder="请输入手机号码" class="layui-input"
                   id="phone">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text" lay-verify="required" placeholder="请输入密码" class="layui-input"
                   id="password">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" lay-verify="required" placeholder="请输入姓名" class="layui-input"
                   id="realname">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">性别 男/女</label>
        <div class="layui-input-block">
            <input type="text" lay-verify="required" placeholder="请输入性别 男/女" class="layui-input"
                   id="sex">
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">积分</label>
        <div class="layui-input-block">
            <input type="text" lay-verify="required" placeholder="请输入积分" class="layui-input"
                   id="point">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">余额</label>
        <div class="layui-input-block">
            <input type="text" lay-verify="required" placeholder="请输入余额" class="layui-input"
                   id="amount">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <a style="display:none;" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="edit"
               id="edit">立即修改</a>
            <a style="display:none;" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="add" id="add">立即提交</a>
            <a class="layui-btn layui-btn-primary close">关闭</a>
        </div>
    </div>
</form>
<script type="text/javascript" src="../../js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/wangEditor.js"></script>
<script type="text/javascript" src="../../js/basic.js"></script>
<script>

    function edit() {
        var id = GetQueryString("id");
        var topM = layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
        $.ajax({
            type: "post",
            url: "/courier/update",
            data: {
                nickname: $("#nickname").val(),
                // headPhoto: $("#headPhoto").val(),

                phone: $("#phone").val(),
                password: $("#password").val(),
                realname: $("#realname").val(),
                birthday: $("#birthday").val(),
                sex: $("#sex").val(),
                bodyTag: $("#bodyTag").val(),
                expTag: $("#expTag").val(),
                wechatOpenid: $("#wechatOpenid").val(),
                qqOpenid: $("#qqOpenid").val(),
                weboOpenid: $("#weboOpenid").val(),
                email: $("#email").val(),
                point: $("#point").val(),
                amount: $("#amount").val(),
                id: id
            },
            dataType: "json",
            success:

                function (data) {
                    backData(data, topM);
                }
        })
        ;
    }

    function add() {
        var topM = layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
        $.ajax({
            type: "post",
            url: "/courier/save",
            data: {
                nickname: $("#nickname").val(),
                // headPhoto: $("#headPhoto").val(),
                token: $("#token").val(),
                status: $("#status").val(),
                phone: $("#phone").val(),
                password: $("#password").val(),
                realname: $("#realname").val(),
                birthday: $("#birthday").val(),
                sex: $("#sex").val(),
                bodyTag: $("#bodyTag").val(),
                expTag: $("#expTag").val(),
                wechatOpenid: $("#wechatOpenid").val(),
                qqOpenid: $("#qqOpenid").val(),
                weboOpenid: $("#weboOpenid").val(),
                email: $("#email").val(),
                point: $("#point").val(),
                amount: $("#amount").val(),
                extra:
                    1
            },
            dataType: "json",
            success:

                function (data) {
                    backData(data, topM);
                }
        })

    };

    function backData(data, topM) {
        if (data.status == 0) {

            setTimeout(function () {
                layer.close(topM);
                top.layer.msg("修改成功！");
                //刷新父页面
                parent.getList({});
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            }, 500);
        } else {
            layer.close(topM);
            layer.msg(data.msg, {icon: 1});
        }
    }

    function begin() {
        var op = GetQueryString("op");
        if (op == "add") {
            $("#add").show();
            return;
        }
        if (op == "edit") {
            $("#edit").show();
        }
        var id = GetQueryString("id");
        $.ajax({
            type: "post",
            url: "/courier/info",
            data: {
                id: id
            },
            dataType: "json",
            success: function (data) {
                if (data.status == 0) {

                    $("#id").val(data.result.id);


                    $("#createTime").val(data.result.createTime);


                    $("#nickname").val(data.result.nickname);


                    $("#headPhoto").val(data.result.headPhoto);


                    $("#token").val(data.result.token);


                    $("#status").val(data.result.status);


                    $("#phone").val(data.result.phone);


                    $("#password").val(data.result.password);


                    $("#realname").val(data.result.realname);


                    $("#birthday").val(data.result.birthday);


                    $("#sex").val(data.result.sex);


                    $("#bodyTag").val(data.result.bodyTag);


                    $("#expTag").val(data.result.expTag);


                    $("#wechatOpenid").val(data.result.wechatOpenid);


                    $("#qqOpenid").val(data.result.qqOpenid);


                    $("#weboOpenid").val(data.result.weboOpenid);


                    $("#email").val(data.result.email);


                    $("#point").val(data.result.point);


                    $("#amount").val(data.result.amount);

                } else {
                    layer.msg(data.msg, {icon: 1});
                }
            }
        });
    }


    //点击取消关闭当前弹窗
    $(".close").click(function () {
//当你在iframe页面关闭自身时
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    })

    layui.use(['form'], function () {
        var form = layui.form;
        //监听提交
        form.on('submit(add)', function (data) {
            add()
            return false;
        });

        //监听提交
        form.on('submit(edit)', function (data) {
            edit()
            return false;
        });
        begin();
    });

</script>
</body>
</html>